package com.example.feature.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.feature.demo.dto.UserQueryDto;
import com.example.feature.demo.entity.Users;
import com.example.feature.demo.mapper.UsersMapper;
import com.example.feature.demo.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhou
 * @since 2021-05-19
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Autowired
    private KafkaTemplate<Object, Object> template;

    @Override
    public IPage<Users> selectPageVo(UserQueryDto dto) {
        Page<Users> page = new Page<Users>(dto.getCurrPage(), dto.getPageSize());
        return this.baseMapper.selectPageVo(page, dto.getUsername());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertUser(Users users) {
        template.send("topic-zhou2", users);
        this.baseMapper.insert(users);
    }
}
